//package com.example.springbootlinmtest.test;
//
//import org.springframework.util.StreamUtils;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletRequestWrapper;
//import java.io.ByteArrayInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//
///**
// * @author Linm
// * @Date 2023/11/2 23:28
// */
//public class CachingRequestBodyFilter implements Filter {
//
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
//            throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        CachedBodyHttpServletRequest cachedBodyHttpServletRequest = new CachedBodyHttpServletRequest(httpServletRequest);
//        filterChain.doFilter(cachedBodyHttpServletRequest, servletResponse);
//    }
//
//// other methods...
//}
//
//class CachedBodyHttpServletRequest extends HttpServletRequestWrapper {
//
//    private byte[] cachedBody;
//
//    public CachedBodyHttpServletRequest(HttpServletRequest request) throws IOException {
//        super(request);
//        InputStream requestInputStream = request.getInputStream();
//        this.cachedBody = StreamUtils.copyToByteArray(requestInputStream);
//    }
//
//    @Override
//    public ServletInputStream getInputStream() throws IOException {
//        return new CachedBodyServletInputStream(this.cachedBody);
//    }
//
//// other methods...
//}
//
//class CachedBodyServletInputStream extends ServletInputStream {
//
//    private ByteArrayInputStream cachedBodyInputStream;
//
//    public CachedBodyServletInputStream(byte[] cachedBody) {
//        this.cachedBodyInputStream = new ByteArrayInputStream(cachedBody);
//    }
//
//    @Override
//    public boolean isFinished() {
//        return cachedBodyInputStream.available() == 0;
//    }
//
//    @Override
//    public boolean isReady() {
//        return true;
//    }
//
//    @Override
//    public void setReadListener(ReadListener readListener) {
//        throw new UnsupportedOperationException();
//    }
//
//    @Override
//    public int read() throws IOException {
//        return cachedBodyInputStream.read();
//    }
//}
